package com.hhcn.friend;


import jdk.nashorn.internal.scripts.JO;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.File;
import java.io.IOException;

/**
 * Created by Administrator on 2018/5/25.
 */
public class Main {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        Configuration conf = new Configuration();
        conf.set("mapreduce.input.keyvaluelinerecordreader.key.value.separator", ",");
        Job job = Job.getInstance(conf, "Friend");

        job.setInputFormatClass(KeyValueTextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        job.setJarByClass(Main.class);

        job.setMapperClass(FriendMap.class);
        job.setReducerClass(FriendReduce.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.waitForCompletion(true);

        Configuration configuration = new Configuration();
        Job jobRecommend = Job.getInstance(configuration,"Recommend");
        jobRecommend.setInputFormatClass(KeyValueTextInputFormat.class);

        jobRecommend.setJarByClass(Main.class);
        jobRecommend.setMapperClass(RecommendMap.class);
        jobRecommend.setReducerClass(RecommendReduce.class);
        FileInputFormat.addInputPath(jobRecommend,new Path(args[1]));
        FileOutputFormat.setOutputPath(jobRecommend,new Path(args[2]));

        System.exit(jobRecommend.waitForCompletion(true) ? 1 : 0);
    }

}
